package com.feilong.modules.common.utils;

/**
 * 单例模式创建雪花算法对象
 */
public class SingletonSnowFlake {

    private static long machineId = 0;

    private static long datacenterId = 0;

    private enum SnowFlakeSingleton{
        Singleton;
        private SnowFlake snowFlake;
        SnowFlakeSingleton(){
            snowFlake = new SnowFlake(datacenterId,machineId);
        }

        public SnowFlake getInstance(){
            return snowFlake;
        }
    }

    public static long generateId(){
        return SnowFlakeSingleton.Singleton.getInstance().nextId();
    }

}
